package com.atguigu.flink.chapter11.hive;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.table.catalog.GenericInMemoryCatalog;

/**
 * @Author lzc
 * @Date 2022/11/1 11:24
 */
public class Flink01_Hive {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 2000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);
        
        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
    
        GenericInMemoryCatalog m1 = new GenericInMemoryCatalog("m1", "d1");
        tEnv.registerCatalog("m1", m1);
        tEnv.useCatalog("m1");
        tEnv.useDatabase("d1");
        
        tEnv.executeSql("create table sensor(" +
                            "id string, " +
                            "ts bigint, " +
                            "vc int" +
                            ")with(" +
                            " 'connector' = 'filesystem', " +
                            " 'path' = 'input/sensor.txt', " +
                            " 'format' = 'csv' " +
                            ")");
        // 在内存: default_catalog.default_database.sensor
//        tEnv.sqlQuery("select * from default_catalog.default_database.sensor").execute().print();
        tEnv.sqlQuery("select * from m1.d1.sensor").execute().print();
        
        
    }
}
